﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EBA.IoC
{
    class ObjectLiveKey
    {
        public Type HostType
        {
            get;
            set;
        }

        public Type InstanceType
        {
            get;
            set;
        }

        public string ContractName
        {
            get;
            set;
        }

        string GetFullName()
        {
            return (this.HostType == null ? "" : this.HostType.FullName) + "," + (this.InstanceType == null ? "" : this.InstanceType.FullName) + this.ContractName;
        }

        public static bool operator !=(ObjectLiveKey key1, ObjectLiveKey key2)
        {
            if (key1.Equals(null) == false && key2.Equals(null) == false)
            {
                return key1.HostType != key2.HostType && key1.InstanceType != key2.InstanceType && key1.ContractName != key2.ContractName;
            }
            else
            {
                return true;
            }
        }

        public static bool operator ==(ObjectLiveKey key1, ObjectLiveKey key2)
        {
            if (key1.Equals(null) == false && key2.Equals(null) == false)
            {
                return key1.HostType == key2.HostType && key1.InstanceType == key2.InstanceType && key1.ContractName == key2.ContractName;
            }
            else
            {
                return false;
            }
        }

        public override bool Equals(object obj)
        {
            if (obj is ObjectLiveKey)
            {
                var key = obj as ObjectLiveKey;

                return key.HostType == this.HostType && key.InstanceType == this.InstanceType;
            }
            else
            {
                return false;
            }
        }

        public override int GetHashCode()
        {
            return this.GetFullName().GetHashCode();
        }
    }
}
